package com.sky.controller.admin;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("AdminSetmealController")
@RequestMapping("/admin/setmeal")
@Api(tags = "后台-套餐管理")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @PostMapping("/status/{status}")
    @ApiOperation(value = "修改套餐售卖状态")
    public Result updateSetmealStatus(@PathVariable Integer status,@RequestParam("id") Integer id) {
        setmealService.updateSetmealStatus(status, id);
        return Result.success();
    }
    @PostMapping
    @ApiOperation(value = "新增套餐")
    public Result saveSetmeal(@RequestBody SetmealDTO setmealDTO) {
        setmealService.saveSetmeal(setmealDTO);
        return Result.success();
    }
    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID获取套餐信息")
    public Result<SetmealVO> getSetmealById(@PathVariable Integer id) {
        SetmealVO setmealWithDishById = setmealService.getSetmealWithDishById(id);
        return Result.success(setmealWithDishById);
    }
    @DeleteMapping
    @ApiOperation(value="批量删除套餐")
    public Result deleteSetmeals(@RequestParam("ids") List<Integer> ids) {
        log.info("批量删除套餐：{}", ids);
        if (ids == null || ids.isEmpty()) {
            return Result.error("请选择需要删除的套餐");
        }
        setmealService.deleteSetmealsByBatch(ids);
        return Result.success();
    }
    @PutMapping
    @ApiOperation(value = "修改套餐")
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO) {
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation(value = "分页获取套餐列表")
    public Result<PageResult> getSetmealPage(SetmealPageQueryDTO setmealPageQueryDTO)
    {
        log.info("获取套餐列表：{}", setmealPageQueryDTO);
        PageResult pageResult = setmealService.getSetmealPage(setmealPageQueryDTO);
        return Result.success(pageResult);
    }
}
